package Eyjafjalla.card.status;

import Eyjafjalla.patch.MelodyPatch;
import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.actions.common.DamageAction;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.cards.CardQueueItem;
import com.megacrit.cardcrawl.cards.DamageInfo;
import com.megacrit.cardcrawl.cards.status.Burn;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.localization.CardStrings;
import com.megacrit.cardcrawl.monsters.AbstractMonster;

public class Burn_Eyjafjalla extends AbstractCard {
    public static final String ID = "Burn_Eyjafjalla";
    private static final CardStrings cardStrings;

    public Burn_Eyjafjalla() {
        this(0);
    }

    public Burn_Eyjafjalla(int times) {
        super("Burn_Eyjafjalla", cardStrings.NAME, "status/burn", -2, cardStrings.DESCRIPTION, CardType.STATUS, CardColor.COLORLESS, CardRarity.COMMON, CardTarget.NONE);
        this.magicNumber = 2;
        this.baseMagicNumber = 2;
        this.timesUpgraded = times;
        this.isMagicNumberModified = true;
    }

    public void use(AbstractPlayer p, AbstractMonster m) {
        if (this.dontTriggerOnUseCard) {
            this.addToBot(new DamageAction(AbstractDungeon.player, new DamageInfo(AbstractDungeon.player, this.magicNumber, DamageInfo.DamageType.THORNS), AbstractGameAction.AttackEffect.FIRE));
        }

    }

    @Override
    public boolean canUse(AbstractPlayer p, AbstractMonster m) {
        if(AbstractDungeon.player.hasRelic("Medical Kit"))
            return true;
        return upgraded&&MelodyPatch.currentSingle!=null;
    }

    @Override
    public void applyPowers() {
        this.isMagicNumberModified = true;
        super.applyPowers();
    }

    public void triggerOnEndOfTurnForPlayingCard() {
        this.dontTriggerOnUseCard = true;
        AbstractDungeon.actionManager.cardQueue.add(new CardQueueItem(this, true));
    }

    public AbstractCard makeCopy() {
        Burn_Eyjafjalla retVal = new Burn_Eyjafjalla(timesUpgraded);
        return retVal;
    }

    public void upgrade() {
        this.upgradeMagicNumber(2);
        ++this.timesUpgraded;
        this.upgraded = true;
        this.name = cardStrings.NAME + "+" + this.timesUpgraded;
        this.initializeTitle();
        if(!rawDescription.equals(cardStrings.UPGRADE_DESCRIPTION)){
            rawDescription = cardStrings.UPGRADE_DESCRIPTION;
            initializeDescription();
        }
    }

    @Override
    public boolean canUpgrade() {
        return false;
    }

    static {
        cardStrings = CardCrawlGame.languagePack.getCardStrings(ID);
    }
}

